package shaopeng.tank;

import java.awt.*;
import java.awt.event.*;

public class TankFrame extends Frame {
    private Tank myTank;
    private Tank enemy;
    private int x=100 , y=100;
    public static final int SPEED=5;
    public TankFrame(){

        this.setLocation(400,100);
        this.setSize(800,600);
        this.setResizable(false);
        this.setTitle("tank war");
        this.setVisible(true);
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
             System.exit(0);
            }
        });

        this.addKeyListener(new TankKeyListener());

        myTank=new Tank(100,100,Dir.R);
        enemy=new Tank(100,200,Dir.R);
    }
    //系统自动调用
    @Override
    public void paint(Graphics g){
        myTank.paint(g);
        enemy.paint(g);

//        x++;
//        System.out.println("paint");
    }
    //内部类
    private class TankKeyListener extends KeyAdapter {


        @Override
        public void keyPressed(KeyEvent e) {
            myTank.keyPressed(e);

        }

        @Override
        public void keyReleased(KeyEvent e) {
          myTank.keyReleased(e);
        }
    }
}
